//
//  TOSearchTableCell.m
//  B段项目
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 张智超. All rights reserved.
//

#import "TOSearchTableCell.h"

@implementation TOSearchTableCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}

#pragma mark - 子视图
-(void)createSubView{
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.mas_equalTo(self).offset(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(self).multipliedBy(0.2);
    }];
    
    self.contentLabel = [[UILabel alloc] init];
    self.contentLabel.numberOfLines = 3;
    [self.contentView addSubview:self.contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(10);
        make.right.mas_equalTo(-self.width*0.1);
        make.bottom.mas_equalTo(-10);
    }];
    
}


-(void)setSearchDetail:(TOSearchDetailModel *)searchDetail
{
   
    _searchDetail = searchDetail;
    
    self.titleLabel.text = self.searchDetail.title;
    self.contentLabel.text = self.searchDetail.shortcontent;

}


-(void)setSearchStr:(NSString *)searchStr{
  
    _searchStr = searchStr;
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc]initWithString:self.titleLabel.text];
    NSRange rangeStr =  [self.titleLabel.text rangeOfString:self.searchStr];
    [attribute setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor redColor]} range:rangeStr];
    self.titleLabel.attributedText = attribute;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
